<?php

class Page extends SiteTree
{

    private static $db = array();

    private static $has_one = array();
}

class Page_Controller extends ContentController
{

    /**
     * An array of actions that can be accessed via a request. Each array element should be an action name, and the
     * permissions or conditions required to allow the user to access it.
     *
     * <code>
     * array (
     *     'action', // anyone can access this action
     *     'action' => true, // same as above
     *     'action' => 'ADMIN', // you must have ADMIN permissions to access this action
     *     'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true
     * );
     * </code>
     *
     * @var array
     */
    private static $allowed_actions = array(
        "CanAccess",
        "FlashMessage"
    );

    public function init()
    {
        parent::init();
        // You can include any CSS or JS required by your project here.
        // See: http://doc.silverstripe.org/framework/en/reference/requirements
    }

    public function FlashMessage()
    {
        if ($message = Session::get(Globals::SESSION_FLASH_MESSAGE)) {
            $status = Session::get(Globals::SESSION_FLASH_STATUS);
            Session::clear(Globals::SESSION_FLASH_MESSAGE);
            Session::clear(Globals::SESSION_FLASH_STATUS);
            return new ArrayData(array(
                "Message" => $message,
                "Status" => $status
            ));
        }

        return false;
    }

    public function setFlashMessage($message, $status = Globals::STATUS_INFO)
    {
        Session::set(Globals::SESSION_FLASH_MESSAGE, $message);
        Session::set(Globals::SESSION_FLASH_STATUS, $status);
    }

    public function createLink($page)
    {
        $link = "/ssprojects/resident-vac";
        $link .= (stripos($page, "/") === 0 ? "" : "/") . $page;

        return $link;
    }
}
